<%--
  Created by IntelliJ IDEA.
  User: DELL
  Date: 2024/8/20
  Time: 10:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
</head>
<body>
<form class="layui-form" action="" lay-filter="Filter">
    <input type="hidden" name="id" id="name">

    <div class="layui-form-item"> <label class="layui-form-label">评价</label>
        <div class="layui-input-block">
            <textarea id="contentId" name="commit" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>


    <%--<div class="layui-form-item"> <label class="layui-form-label">创建时间</label>
        <div class="layui-input-block">
            <input type="text" name="createTime" placeholder="请输创建时间" autocomplete="off" class="layui-input">
        </div>
    </div>--%>
    <div class="layui-form-item">
        <div class="layui-input-block"> <button type="submit" class="layui-btn" lay-submit="" lay-filter="formFilter">立即提交</button> <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script src="/static/js/jquery-2.1.4.js"></script>
<script src="/static/js/mylayer.js"></script>
<script src="/static/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="/static/kindeditor/kindeditor/kindeditor.js" type="text/javascript" charset="utf-8"></script>
<script>
    //富文本编辑器

    //富文本编辑器
    var kindEditorParams = {
        afterBlur: function() {
            this.sync();
        }
    };
    //关联一下
    var contentId = KindEditor.create('#contentId',kindEditorParams);

    layui.use(['form'], function() {
        var form = layui.form;
        var upload = layui.upload;
        var layer = layui.layer;
        var element = layui.element;
        var $ = layui.$;

        //获取id值
        var queryString = window.location.search;
        var urlParams = new URLSearchParams(queryString);
        var id = urlParams.get("id");
        //先查找，再添加
        //写一个Ajax请求，获取当前id下的所有blog值
        $.post(
            //虽然是在blog里调用的是selectById方法，但是要把type的selectAll一起打包发回来
            '/project?method=selectById',
            //把id传过去
            {"id":id},//应该只用传id吗
            function (result) {
                console.log('id:'+id)
                console.log('result:')
                console.log(result);
                form.val('Filter',result.data);
                //$('#name').val(result.data.id)
                contentId.html(result.data.commit);//contentId是kindEditor的名字
                //form.val('Filter',result.data);

            },
            'json'

        )
        //监听提交
        form.on('submit(formFilter)', function (data) {
            console.log('data.field');
            console.log(data.field);
            $.post(
                '/project?method=update',
                data.field,
                function (result) {
                    console.log(result)
                    if (result.code == 0){
                        mylayer.okMsg(result.msg);
                        //关闭弹窗
                        setInterval(function () {
                            //关闭弹出层
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            //刷新父页面
                            window.parent.location.reload();
                        }, 2000);
                    }
                },
                'json'
            )

            /* layer.alert(JSON.stringify(data.field), {
                 title: '最终的提交信息'
             })
             return false;*/
            return false;
        });
        //下拉框
       /* $.post(
            '/project?method=selectAll',
            function (jsonObj){
                console.log(jsonObj);
                //遍历
                $(jsonObj.data).each(function() {
                    $('#typeId').append('<option value="'+this.id+'">'+this.name+'</option>');
                });

                // 更新表单选择框
                form.render('select');
            },
            'json'
        )*/
        // 单图片上传


    })
</script>
</body>
</html>
